package com.reservation.controller.staff;

import com.reservation.dto.staff.AuditDTO;
import com.reservation.result.Result;
import com.reservation.service.StaffService;
import com.reservation.vo.staff.WaitAuditItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "员工取消预约审核接口")
@RestController
@RequestMapping("/api/staff")
@Slf4j
public class AuditController {

    @Autowired
    private StaffService staffService;

    /**
     * 获取待审核取消预约列表
     *
     * @return 待审核列表
     */
    @ApiOperation(value = "获取待审核取消预约列表")
    @PostMapping("/getWaitAuditList")
    public Result<List<WaitAuditItemVO>> getWaitAuditList() {
        log.info("获取待审核取消预约列表");
        List<WaitAuditItemVO> list = staffService.getWaitAuditList();
        return Result.success(list);
    }

    /**
     * 审核通过取消预约申请（需客户确认）
     *
     * @param auditDTO 审核信息
     * @return 处理结果
     */
    @PostMapping("/auditPass")
    @ApiOperation("审核通过取消预约申请")
    public Result<String> auditPass(@Valid @RequestBody AuditDTO auditDTO) {
        log.info("审核通过取消预约申请：{}", auditDTO);
        staffService.auditPass(auditDTO.getId());
        return Result.success("审核通过成功，等待客户确认退款");
    }

    /**
     * 审核拒绝取消预约申请
     *
     * @param auditDTO 审核信息
     * @return 处理结果
     */
    @PostMapping("/auditFail")
    @ApiOperation("审核拒绝取消预约申请")
    public Result<String> auditFail(@Valid @RequestBody AuditDTO auditDTO) {
        log.info("审核拒绝取消预约申请：{}", auditDTO);
        boolean success = staffService.auditFail(auditDTO.getId());
        return success ? Result.success("审核拒绝成功") : Result.error("审核处理失败");
    }


}
